package com.javacoo.event.client.starter;

import java.util.Optional;

import com.javacoo.event.client.api.EventHelper;
import com.javacoo.event.client.context.EventContext;

import lombok.extern.slf4j.Slf4j;

/**
 * 事件对象持有者
 * <li></li>
 *
 * @author: duanyong
 * @since: 2021/10/15 22:56
 */
@Slf4j
public class EventHolder {
    /** 事件上下文*/
    static EventContext eventContext = new EventContext();
    /** 事件帮助类接口对象*/
    static EventHelper eventHelper;
    /**
     * 获取EventHelper
     * <li></li>
     * @author duanyong@jccfc.com
     * @date 2021/10/21 9:03
     * @return: java.util.Optional<com.javacoo.event.client.api.EventHelper>
     */
    public static Optional<EventHelper> getEventHelper() {
        return Optional.ofNullable(eventHelper);
    }
    /**
     * 注册事件监听对象
     * <li>这里只是将监听对象存入上下文,待组件初始化完成才注册</li>
     * @author duanyong@jccfc.com
     * @date 2021/10/21 9:05
     * @param listeningObject:
     * @return: void
     */
    public static void register(Object listeningObject){
        log.info("注册事件监听对象:{}",listeningObject);
        eventContext.addListeningObject(listeningObject);
    }
    /**
     * 获取EventContext
     * <li></li>
     * @author duanyong@jccfc.com
     * @date 2021/10/21 11:31
     * @return: com.javacoo.event.client.context.EventContext
     */
    public static EventContext getEventContext(){
        return eventContext;
    }

}
